<?php 
namespace App\Models;

class ShortMsgRecord extends BaseModel{
	
	//表明
	protected $table = 'short_msg_record';
	//主键
	protected $primaryKey = 'id';
    
    protected $LIMIT_NUM = 6;


    //短信安全性验证 次数限制
	public function sendMsgAuth(){
        $phone = $this->request->input('phone');
        $tn = $this->request->input('tn');
        $dk = $this->request->input('dk');
        $ip = $this->request->ip();
        
		//dk 验证 
		$date_line = strtotime(date('Y-m-d'));
		$num1 = ShortMsgRecord::select('id')
			->where('dk','=',$dk)
			->where('created_at','>',$date_line)
			->count();
		//IP 验证
		$num2 = ShortMsgRecord::select('id')
			->where('remote_addr','=',$ip)
			->where('created_at','>',$date_line)
			->count();
		//账号 验证
		$num3 = ShortMsgRecord::select('id')
			->where('phone','=',$phone)
			->where('created_at','>',$date_line)
			->count();
        //token 验证 
        $num4 = ShortMsgRecord::select('id')
			->where('tn','=',$tn)
			->where('created_at','>',$date_line)
			->count();
		if($num1 > $this->LIMIT_NUM ||$num2 > 50|| $num3 >$this->LIMIT_NUM || $num4 >$this->LIMIT_NUM){
			return FALSE;
		}
		return TRUE;
	}
}